<template>
  <div class="ele-body">
    <el-card shadow="never" body-style="padding-top: 5px;">
          <el-form :model="form" ref="form" label-width="150px">
            <el-form-item  label="平台名称" prop="site_name">
              <el-input v-model="form.site_name" placeholder="请输入" clearable/>
            </el-form-item>
            <el-form-item  label="平台Logo" prop="site_logo">
              <uploadImage :limit="1" v-model="form.site_logo"></uploadImage>
            </el-form-item>
            <el-form-item  label="平台说明" prop="site_desc">
              <el-input v-model="form.site_desc" placeholder="请输入" type="textarea"/>
            </el-form-item>
          </el-form>
          <div style="margin-left: 150px;">
            <el-button type="primary" @click="save" :loading="loading">保存更改</el-button>
          </div>
    </el-card>
  </div>
</template>

<script>
import uploadImage from '@/components/uploadImage'

export default {
  name: "ConfigWeb",
  components: {uploadImage},
  data() {
    return {
      loading: false,  // 保存按钮loading
      form: {},  // 表单数据
    }
  },
  computed: {
  },
  mounted() {
    this.getConfigInfo();
  },
  methods: {
    // 获取配置信息
    getConfigInfo() {
      this.$http.get('/configweb/index').then(res => {
        if (res.data.code === 0) {
          this.configList = res.data.data;
          if (this.configList.length > 0) {
            let itemList = this.configList[0]['item_list'];
            let itemArr = {};
            itemList.forEach(item => {
              itemArr[item.code] = item.value;
            })
            this.form = itemArr;
          } else {
            this.form = {};
          }
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    },
    /* 保存更改 */
    save() {
      this.loading = true;
      this.$http.post('/configweb/edit', this.form).then(res => {
        this.loading = false;
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          window.location.reload()
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.loading = false;
        this.$message.error(e.message);
      });
    },
  }
}
</script>
